import request from '@/utils/request'
import type { BaseResponse } from '@/types/common/response'
import type { Menu, MenuTree, CreateMenuRequest, UpdateMenuRequest, UpdateMenuStatusRequest } from '@/types/api/menu'

/**
 * 菜单管理相关API
 */
export const menuApi = {
  /**
   * 获取菜单列表
   */
  getMenuList() {
    return request.get<BaseResponse<MenuTree[]>>('/menus')
  },

  /**
   * 获取菜单详情
   * @param id 菜单ID
   */
  getMenuDetail(id: number) {
    return request.get<BaseResponse<Menu>>(`/menus/${id}`)
  },

  /**
   * 创建菜单
   * @param data 菜单信息
   */
  createMenu(data: CreateMenuRequest) {
    return request.post<BaseResponse<null>>('/menus', data)
  },

  /**
   * 更新菜单
   * @param id 菜单ID
   * @param data 菜单信息
   */
  updateMenu(id: number, data: UpdateMenuRequest) {
    return request.put<BaseResponse<null>>(`/menus/${id}`, data)
  },

  /**
   * 删除菜单
   * @param id 菜单ID
   */
  deleteMenu(id: number) {
    return request.delete<BaseResponse<null>>(`/menus/${id}`)
  },

  /**
   * 更新菜单状态
   * @param id 菜单ID
   * @param data 状态信息
   */
  updateMenuStatus(id: number, data: UpdateMenuStatusRequest) {
    return request.put<BaseResponse<null>>(`/menus/${id}/status`, data)
  }
}
